<?
if(!function_exists('stripHTML')){
	function stripHTML($str, $keepBasicTags=false) {
		$patterns = array(
			'@<(script|style)[^>]*>.*?</\1>@si',
			'@</?(?:a|strong|b|em|i|strike|u|sub|sup|span|address|font|cite|abbr|acronym|del|ins)\b[^>]*>@i',
			'@<[\w/!-]+[^>]*>@'
		);
		$replacements = array(' ', '', ' ');

		if($keepBasicTags) {
			unset($patterns[1], $replacements[1]);
			$basicTags = 'a|abbr|acronym|address|b|blockquote|br|cite|code|dd|del|dfn|div|dl|dt|em|h[1-6]|hr|i|img|ins|kbd|li|ol|p|pre|q|s|samp|span|strike|strong|sub|sup|u|ul|var';
			$patterns[2] = '@<(?!/?('.$basicTags.')/?(>|\s))[\w\/!-]+[^>]*>@i';
		}
		$str = trim(str_replace(
			array('&nbsp;', '&#9;', '\xc2\xa0\x20', '　', '&#39;', '&#039;', '&apos;', '&quot;', '&lt;', '&gt;', '&amp;'),
			array(' ', ' ', ' ', ' ', '\'', '\'', '\'', '"', '<', '>', '&'),
			preg_replace($patterns, $replacements, $str)
		));
		return $keepBasicTags ? $str : preg_replace('@\s+@', ' ', $str);
	}
}

if(!function_exists('removeAllTags')){
	function removeAllTags($contents){
		$contents=preg_replace('/\[#M_[^|]*\|[^|]*\|/Us','',str_replace('_M#]','',preg_replace('/\[##_.+_##\]/Us','',$contents)));
		$contents=preg_replace('@(<s_|</s_)[0-1a-zA-Z_]+>@','',$contents);
		return $contents;
	}
}

if(!function_exists('encodeURL')){
	function encodeURL($url) {
		global $service;
		if (@$service['useEncodedURL'])
			return str_replace('%2F', '/', rawurlencode($url));
		else
			return str_replace(array('%', ' ', '"', '#', '&', '\'', '<', '>', '?'), array('%25', '%20', '%22', '%23', '%26', '%27', '%3C', '%3E', '%3F'), $url);
	}
}
if(!function_exists('getTags')){
	function getTags($entry) {
		global $database, $blogid;
		$tags = array();
		$result = mysql_query("SELECT * FROM `{$database['prefix']}Tags` t, `{$database['prefix']}TagRelations` r, `{$database['prefix']}Entries` e WHERE r.entry = e.id AND e.visibility > 0 AND t.id = r.tag AND r.entry = $entry AND r.blogid = $blogid GROUP BY r.tag ORDER BY t.name");
		if ($result!==false) {
			while (($tag = mysql_fetch_array($result)) !== false)
				array_push($tags, $tag);
		}
		return $tags;
	}
}
?>
